/*
    Copyright (C) 2021 Huawei Device Co., Ltd.
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 */

package agency.tango.materialintroscreen.interceptor;

/**
 * @ProjectName: material-intro-screen-master
 * @Package: agency.tango.materialintroscreen.interceptor
 * @ClassName: DecelerateInterpolator
 * @Description: An interpolator where the rate of change starts out
 * quickly and then decelerates.
 * @CreateDate: 2021/4/12 16:18
 * @UpdateDate: 2021/4/12 16:18
 * @UpdateRemark: 暂无
 * @Version: 1.0
 */
public class DecelerateInterpolator extends BaseInterpolator {
    private float mFactor = 1.0f;

    public DecelerateInterpolator() {
    }

    /**
     * Constructor
     *
     * @param factor Degree to which the animation should be eased. Setting
     *               factor to 1.0f produces
     *               an upside-down y=x^2 parabola. Increasing factor above 1
     *               .0f makes exaggerates the
     *               ease-out effect (i.e., it starts even faster and ends
     *               evens slower)
     */
    public DecelerateInterpolator(float factor) {
        mFactor = factor;
    }

    /**
     * 获取插值
     *
     * @param input A value between 0 and 1.0 indicating our current point
     *              in the animation where 0 represents the start and 1.0 represents
     *              the end
     * @return 插值
     */
    public float getInterpolation(float input) {
        return getCurvedTime(input);
    }

    /**
     * 获取插值
     *
     * @param input 输入时间
     * @return 插值
     */
    @Override
    public float getCurvedTime(float input) {
        float result;
        if (mFactor == 1.0f) {
            result = 1.0f - (1.0f - input) * (1.0f - input);
        } else {
            result = (float) (1.0f - Math.pow((1.0f - input), 2 * mFactor));
        }
        return result;
    }
}

